#pragma once
#include<string>
#include<unordered_map>
namespace bitpr{

    //字段宏
    #define KEY_METHOD      "method" //方法名称
    #define KEY_PARAMS      "parameters" //方法参数
    #define KEY_TOPIC_KEY   "topic_key" //主题名称
    #define KEY_TOPIC_MSG   "topic_msg" //主题消息
    #define KEY_OPTYPE      "optype" //操作类型
    #define KEY_HOST        "host" //主机信息
    #define KEY_HOST_IP     "ip"  //ip
    #define KEY_HOST_PORT   "port" //port
    #define KEY_RCODE       "rcode"//响应码
    #define KEY_RESULT      "result"//响应结果


    //消息类型定义
    enum  class MType{
        REQ_RPC = 0,
        RSP_RPC,
        REQ_TOPIC,
        RSP_TOPIC,
        REQ_SERVICE,
        RSP_SERVICE
    };
    //响应码
    enum class RCode{
        RCODE_OK=0,
        RCODE_PARSE_FAILED,
        RCODE_INVALID_MSG,
        RCODE_IDSCONNECTED,
        RCODE_INVAILD_PARAMS,
        RCODE_NOT_FOUND_SERVICE,
        RCODE_INVAILD_OPTYPE,
        RCODE_NOT_FOUND_TOPIC,
        RCODE_INTERNAL_ERROR

    };

    static std::string errReason(RCode code){
        static std::unordered_map<RCode,std::string>err_map={
            {RCode::RCODE_OK,"成功处理"},
            {RCode::RCODE_PARSE_FAILED,"消息解析失败"},
            {RCode::RCODE_INVALID_MSG,"无效消息"},
            {RCode::RCODE_IDSCONNECTED,"链接断开"},
            {RCode::RCODE_INVAILD_PARAMS,"无效的Rpc参数"},
            {RCode::RCODE_NOT_FOUND_SERVICE,"没有找到对应的操作"},
            {RCode::RCODE_INVAILD_OPTYPE,"无效的操作类型"},
            {RCode::RCODE_NOT_FOUND_TOPIC,"没有找到对应的主题"},
            {RCode::RCODE_INTERNAL_ERROR,"内部错误"},


        };
        auto it =err_map.find(code);
        if(it==err_map.end())
        {
            return "位置错误";
        }
        return it->second;
    };
    //Rpc请求方式
    enum class RType{
        REQ_SYNC=0,
        REQ_ASYNC,
        REQ_CALLBACK
    };
    enum class TopicOptype{
        TOPIC_CREATE = 0,
        TOPIC_REMOVE,
        TOPIC_SUBSCRIBE,
        TOPIC_CANCEL,
        TOPIC_PUBLISH
    };
    enum class ServiceOptype {
        SERVICE_REGISTRY = 0,
        SERVICE_DISCOVERY,
        SERVICE_ONLINE,
        SERVICE_OFFLINE,
        SERVICE_UNKNOW
    };


}